import request from '@/router/axios';
import {baseUrl} from '@/config/env';

export const getList = (page, limit, params, parentId) => {
  return request({
    url: baseUrl + '/api/code/getpages',
    method: 'get',
    params: {
      key:params.name==undefined?'':params.name,
      type:params.code==undefined?'':params.code,
      where:parentId,
      page,
      limit,
    }
  })
}

export const remove = (ids) => {
  return request({
    url: baseUrl + '/api/code/remove',
    method: 'post',
    params: {
      ids,
    }
  })
}

export const add = (row) => {
  return request({
    url: baseUrl + '/api/code/add',
    method: 'post',
    data: row
  })
}

export const update = (row) => {
  return request({
    url: baseUrl + '/api/code/edit',
    method: 'post',
    data: row
  })
}

export const getDict = (id) => {
  return request({
    url: baseUrl + '/api/code/detail',
    method: 'get',
    params: {
      id,
    }
  })
}

export const getDictTree = () => {
  return request({
    url: baseUrl + '/api/codetype/gettree',
    method: 'get'
  })
}

export const treeRemove = (id) => {
  return request({
    url: baseUrl + '/api/codetype/remove',
    method: 'post',
    params: {
      id,
    }
  })
}

export const treeAdd = (row) => {
  return request({
    url: baseUrl + '/api/codetype/add',
    method: 'post',
    data: row
  })
}

export const treeUpdate = (row) => {
  return request({
    url: baseUrl + '/api/codetype/edit',
    method: 'post',
    data: row
  })
}

export const getCodes = (tid) => {
  return request({
    url: baseUrl + '/api/code/getCodes',
    method: 'get',
    params: {
      typeId:tid,
    }
  })
}
